<?php
                                                                                                                                                                                                                                                                                                                                        
// TTTTTTTTTTTTTTTTTTTTTTT                  MMMMMMMM               MMMMMMMM                                CCCCCCCCCCCCMMMMMMMM               MMMMMMMM  SSSSSSSSSSSSSSS 
// T:::::::::::::::::::::T                  M:::::::M             M:::::::M                             CCC::::::::::::M:::::::M             M:::::::MSS:::::::::::::::S
// T:::::::::::::::::::::T                  M::::::::M           M::::::::M                           CC:::::::::::::::M::::::::M           M::::::::S:::::SSSSSS::::::S
// T:::::TT:::::::TT:::::T                  M:::::::::M         M:::::::::M                          C:::::CCCCCCCC::::M:::::::::M         M:::::::::S:::::S     SSSSSSS
// TTTTTT  T:::::T  TTTTTppppp   ppppppppp  M::::::::::M       M::::::::::M   eeeeeeeeeeee          C:::::C       CCCCCM::::::::::M       M::::::::::S:::::S            
//         T:::::T       p::::ppp:::::::::p M:::::::::::M     M:::::::::::M ee::::::::::::ee       C:::::C             M:::::::::::M     M:::::::::::S:::::S            
//         T:::::T       p:::::::::::::::::pM:::::::M::::M   M::::M:::::::Me::::::eeeee:::::ee     C:::::C             M:::::::M::::M   M::::M:::::::MS::::SSSS         
//         T:::::T       pp::::::ppppp::::::M::::::M M::::M M::::M M::::::e::::::e     e:::::e     C:::::C             M::::::M M::::M M::::M M::::::M SS::::::SSSSS    
//         T:::::T        p:::::p     p:::::M::::::M  M::::M::::M  M::::::e:::::::eeeee::::::e     C:::::C             M::::::M  M::::M::::M  M::::::M   SSS::::::::SS  
//         T:::::T        p:::::p     p:::::M::::::M   M:::::::M   M::::::e:::::::::::::::::e      C:::::C             M::::::M   M:::::::M   M::::::M      SSSSSS::::S 
//         T:::::T        p:::::p     p:::::M::::::M    M:::::M    M::::::e::::::eeeeeeeeeee       C:::::C             M::::::M    M:::::M    M::::::M           S:::::S
//         T:::::T        p:::::p    p::::::M::::::M     MMMMM     M::::::e:::::::e                 C:::::C       CCCCCM::::::M     MMMMM     M::::::M           S:::::S
//       TT:::::::TT      p:::::ppppp:::::::M::::::M               M::::::e::::::::e                 C:::::CCCCCCCC::::M::::::M               M::::::SSSSSSS     S:::::S
//       T:::::::::T      p::::::::::::::::pM::::::M               M::::::Me::::::::eeeeeeee          CC:::::::::::::::M::::::M               M::::::S::::::SSSSSS:::::S
//       T:::::::::T      p::::::::::::::pp M::::::M               M::::::M ee:::::::::::::e            CCC::::::::::::M::::::M               M::::::S:::::::::::::::SS 
//       TTTTTTTTTTT      p::::::pppppppp   MMMMMMMM               MMMMMMMM   eeeeeeeeeeeeee               CCCCCCCCCCCCMMMMMMMM               MMMMMMMMSSSSSSSSSSSSSSS   
//                        p:::::p                                                                                                                                       
//                        p:::::p                                                                                                                                       
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       ppppppppp                                                                                                                                      
                                                                                                                                                                     
//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/07/27
//      |_|                                         | TpMeCMS

namespace app\api\controller;
use app\api\controller\Tpmecms;
use think\Db;
use think\Config;
use fast\Random;
use fast\Http;
use think\Request;

/**
 * 支付💰
 */
class Pay extends Tpmecms
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $pay_role = 1;//支付角色 2司机端 1货主端
    public $domain; //  域名
    public $_params;//支付设置
    public function _initialize()
    {
        parent::_initialize();
    }

    public function __construct($pay_role=null)
    {
        if(isset($pay_role))
        $this->pay_role = $pay_role;
        $request = Request::instance();
        $this->domain = $request->domain();
    }


    // /**
    //  * @ApiInternal
    //  * 🔐获取微信支付配置
    //  *
    //  * @param integer $pay_role 1默认货主,2=司机
    //  * @return void
    //  */
    // public function get_wxpay_params($pay_role=1){
    //     $config = Config::get('site');
    //     if($pay_role==1){
    //         $params = new \Yurun\PaySDK\Weixin\Params\PublicParams;
    //         $params->appID = $config['app_id'];//appid
    //         $params->mch_id = $config['mch_id'];//商户号
    //         $params->key = $config['key'];//秘匙
    //     }else{
    //         //司机端
    //         $params = new \Yurun\PaySDK\Weixin\Params\PublicParams;
    //         $params->appID = $config['driver_app_id'];//appid
    //         $params->mch_id = $config['driver_mch_id'];//商户号
    //         $params->key = $config['driver_key'];//秘匙
    //     }
    //     return $params;      
    // }


    // /**
    //  * @ApiInternal
    //  * 获取支付宝支付配置
    //  *
    //  * @return void
    //  */   
    // public function get_alipay_params(){
    //     $params = new \Yurun\PaySDK\AlipayApp\Params\PublicParams;
    //     $config = Config::get('site');

    //     $params->appID = $config['ali_app_id'];
    //     $params->apiDomain = $config['ali_apiDomain'];
    //     $params->format = 'JSON';
    //     $params->sign_type = 'RSA2';
    //     // $params->isUseAES = true;
    //     // // 使用公钥证书模式
    //     $params->usePublicKeyCert = true;
    //     // 支付宝公钥证书文件路径
    //     $params->alipayCertPath = './cert/alipayCertPublicKey_RSA2.crt';
    //     // 支付宝根证书文件路径
    //     $params->alipayRootCertPath = './cert/alipayRootCert.crt';
    //     // 支付宝应用公钥证书文件路径
    //     $params->merchantCertPath = './cert/appCertPublicKey_2021002181608598.crt';

    //     $params->aesKey   = '2deHluumqLLVvDmE/ptZCA==';
       
    //     //应用公钥2048
    //     $params->appPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlsxYl24wNXmEIwUmNpalU0WXooBE4BiTXiMrNiZeFDJQxLJ0E+tq0a9PLSxHtSoCEpopv/UWPUB9JpxV2ZRe/HexC8lW70NG9uNQURzVD/0NQMTCu8zTMygMxDyaJ1AS+HtoD/oSoiQ/kNDrvLRpUAmss+DYPWxZtuLx4kIDkIjZ8ZkrShTGFcGr7EhUkmsGIWUxdmtq4HG/Lp7noW1yMBUUWUUFMqfr0dKu4c+e1Eiz73dPPhyGOroD8ZZt1BfkU7kKv1qKP01luiqles7eByS29pMu9UTOdZi11QCloJp5S6BByYov+LDNn2YkAr/fXbfRwnOvqAgnmd3sn0FnsQIDAQAB';//$appPublicKey;
    //     //应用私钥2048.txt   支付宝开发工具生成
    //     $params->appPrivateKey = 'MIIEpAIBAAKCAQEAlsxYl24wNXmEIwUmNpalU0WXooBE4BiTXiMrNiZeFDJQxLJ0E+tq0a9PLSxHtSoCEpopv/UWPUB9JpxV2ZRe/HexC8lW70NG9uNQURzVD/0NQMTCu8zTMygMxDyaJ1AS+HtoD/oSoiQ/kNDrvLRpUAmss+DYPWxZtuLx4kIDkIjZ8ZkrShTGFcGr7EhUkmsGIWUxdmtq4HG/Lp7noW1yMBUUWUUFMqfr0dKu4c+e1Eiz73dPPhyGOroD8ZZt1BfkU7kKv1qKP01luiqles7eByS29pMu9UTOdZi11QCloJp5S6BByYov+LDNn2YkAr/fXbfRwnOvqAgnmd3sn0FnsQIDAQABAoIBAGIRKlvwcLGWAPS1WJCPj5yD2YT4XdJOqSfDP0rL0MrZneUNGKgLpUAP/jGmZkvOseJfF1+ah4f19G2zpbEF6G/PdvfvS/X1jqToV0cotPbc3k2MqAdxwLe4B/VmY+nFDVFDD/2z54JCiIQpGeVyfjpq0EF6q6XmXMGu/RbjT2YiU5j8AlqKnZyM74QrXLONUuKw+/ObPXbmSIYncKD0VBhtcGTW3JacGsm9nGEoPNwXC9QyO+LKCodbwga+mq1zrCTieoZxpaDwWOmqfMc4zRuCofvzfe3jQ6zjJ2SrbEtSMfG/Nnmwm7uQ+lE1q+yGRFhA0IGdz6JqV+ZZm/YrAkECgYEA9VPb3yfROz4qlpF0CMAtjOie+7iV0KWSMcPT8+tjDJ+n54AL0s+LmcWPtjRiTRn7GQ32cAeBNo/UL2YC1qlwMFO7gXT8khhaO2t84bgQIGLzh3DfXfDaIrOr5kAJIwnzWD3KoCbvamvwSoDR2YyVC9kyzdNgrNAxAAYWTjdB4m0CgYEAnVu92p5OQdTP1UUj6f4l45wr+CicrYKeAx6ImUYYr6H02L4sn1yMGzudcQ53KGyy5njbSEYqBPYiZGZIsSmn6OcJDGV3uZ7H9HPNj5C8pgWMVRV3f8zWNAJ3dv+Bp8no9BnpqwAADtQzrs9jgr3x1KfhGoEFHcybuUS5Z8WWL9UCgYAeVghSR/IviThq9gGLM3hufDVsmx6rdk3lqXmEKA9PeE6i6cqMfu2cTjm/JishrZzHNFrM76CixpZOZibjtIAS+cet8nFo/2no/xmqL8COwK2sieCVFTtkHyOajUCT/J8CwmFT/HyOhFpqXBOW+zNTC8CkgwbpV7U3c4k+ksaq4QKBgQCF95wL6qivbTG/3Uw1I1U4kTXx4Ql6wvApsa4T59SOenDMsiOlTRJPARMKNImH1fr9MjlmL64IaVBgb6BFjDRSmZdfgWdLlX2ghZKlPlENez29FjiVilt3Df6NRfwpUEHOx9zi424pMcoKcq/CmFmxdXe0q9EiTJbrRTIfwd0aPQKBgQCCAP9mydZr0OxwAgvn8kHmyQBPcNDwUO7sgYaDplxEKFiYKAhgFDA6pyP8vbQKXWRnl3mm54U8yKMqBBOgjWgX9fJjx7r2j2sRuSbJy8xw1w6y/Uxo5wzH+qaxev/vGQ3wJTzcDf3w1i4I4BCDnTbut1MnEE/mV0WiYIuFkA/5Gg==';

    //     return $params;      
    // }

    /**
     * 
     * 🔐阿里支付订单💰
     *
     * @param array $data 订单信息
     * @return void
     */
    public function ali_pay_order($data)
    {
        $params = $this->get_alipay_params($this->pay_role);

        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\AlipayApp\SDK($params);
        // 支付接口
        $request = new \Yurun\PaySDK\AlipayApp\App\Params\Pay\Request;
        if($this->pay_role==1){
            $request->notify_url = 'http://jiell.cn/api/query_pay/ali_pay_callback';
        }else{
            $request->notify_url = 'http://jiell.cn/api/query_pay/ali_driver_pay_callback';
        }
            //$GLOBALS['PAY_CONFIG']['notify_url'];// 支付后通知地址（作为支付成功回调，这个可靠）
        $request->businessParams->out_trade_no = $data['order']; // 商户订单号
        $request->businessParams->total_amount = $data['money']; // 价格
        $request->businessParams->subject = '捷拉拉-押金支付'; // 商品标题

        $request->businessParams->goods_type = "0";//商品主类型：0—虚拟类商品，1—实物类商品（默认）

        $request->businessParams->body = $data['order_status']; // 商品标题
        $request->businessParams->time_expire = date('Y-m-d H:i:s',time()+600);

        $request->businessParams->timeout_express = "10m";
        $request->businessParams->return_params='PayOrder'.$data['order_status'];
        // 处理
        $pay->prepareExecute($request, $url, $res);

        return http_build_query($res);
        $this->success(http_build_query($res),http_build_query($res));
        echo $url; // 输出的是可以让app直接请求的url
        echo http_build_query($res); // 输出的是可以让app直接使用的参数
    }





    /**
     * 🔐阿里充值钱包💰
     *
     * @param array $data 订单信息
     * @return void
     */
    public function ali_pay_money_order($data)
    {
        // $this->ali_app_pay_money_order2($data);
        $this->_params = $this->get_alipay_params($this->pay_role);
        // halt($this->_params);
        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\AlipayApp\SDK($this->_params);
       
        // 支付接口
        $request = new \Yurun\PaySDK\AlipayApp\App\Params\Pay\Request;
        if($this->pay_role==1){
            $request->notify_url = 'http://jiell.cn/api/query_pay/ali_pay_callback';
        }else{
            $request->notify_url = 'http://jiell.cn/api/query_pay/ali_driver_pay_callback';
        }
        // $request->notify_url = $this->domain.'/api/query_pay/ali_pay_money_order_query?order='.$data['order'];//$GLOBALS['PAY_CONFIG']['notify_url'];// 支付后通知地址（作为支付成功回调，这个可靠）
        // $request->return_url = $this->domain;
        $request->businessParams->out_trade_no = $data['order']; // 商户订单号
        $request->businessParams->total_amount = $data['money']; // 价格
        $request->businessParams->subject = Config::get('site.name').'充值'; // 商品标题
        $request->businessParams->body = $this->pay_role==1?'货主充值':'司机充值'; // 商品标题
        $request->businessParams->time_expire = date('Y-m-d H:i:s',time()+600);

        $request->businessParams->timeout_express = "10m";
        $request->businessParams->goods_type = "0";//商品主类型：0—虚拟类商品，1—实物类商品（默认）
        $request->businessParams->return_params="pay_money";

        
        // halt($pay);
        $pay->prepareExecute($request, $url, $res);
        // halt($res);
        // $this->error('no');

        // $this->success($res,http_build_query($res));

        return http_build_query($res); // 输出的是可以让app直接使用的参数
    }

    /**
     * 查询阿里支付钱包
     *
     * @param string $order
     * @return void
     */
    public function query_ali_pay_money($order='Money2021122113184415')
    {
        $order_data = Db::name('money_order')->where('order',$order)->find();
        if(!$order_data){
            $this->error('没有该订单信息');
        }
        // halt($order_data);
        

        $this->_params = $this->get_alipay_params($order_data['pay_role']);
        $pay = new \Yurun\PaySDK\AlipayApp\SDK($this->_params);

        // 支付接口
        $request = new \Yurun\PaySDK\AlipayApp\Params\Query\Request();
        // $request->notify_url = $this->domain.'/api/pay/query_ali_pay_money';// 支付后通知地址（作为支付成功回调，这个可靠）
        // $request->return_url = $this->domain; // 支付后跳转返回地址
        // if($order_data['pay_role']==1){
        //     $request->notify_url = 'http://jiell.cn/api/query_pay/ali_pay_callback';
        // }else{
        //     $request->notify_url = 'http://jiell.cn/api/query_pay/ali_driver_pay_callback';
        // }
        
        $request->businessParams->out_trade_no = $order; // 订单支付时传入的商户订单号,和支付宝交易号不能同时为空。
        // $request->businessParams->trade_no = ''; // 支付宝交易号，和商户订单号不能同时为空

        // 调用接口
        $result = $pay->execute($request);

        var_dump('result:', $result);
    }






    /**
     * 微信支付订单
     * @ApiWeigh (999)
     * @param array $data 订单信息
     * @return void
     */
    public function wx_pay_order($data)
    {
        // halt($data);
        //微信
        $this->_params = $this->get_wxpay_params($this->pay_role);
    
        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\Weixin\SDK($this->_params);
        // 支付接口
        $request = new \Yurun\PaySDK\Weixin\APP\Params\Pay\Request;
        $request->body = '捷拉拉-押金支付';//.$data['order_status']; // 商品描述
        $request->out_trade_no = $data['order']; // 订单号
        $request->total_fee = $data['money']*100; // 订单总金额，单位为：分
        // $request->spbill_create_ip = '127.0.0.1'; // 客户端ip，必须传正确的用户ip，否则会报错
        $request->notify_url = $this->domain.'/api/query_pay/wechat_query_pay_order?order='.$data['order'];//$GLOBALS['PAY_CONFIG']['pay_notify_url']; // 异步通知地址
        // $request->scene_info->store_id = '门店唯一标识，选填';
        // $request->scene_info->store_name = '门店名称，选填';
        // 调用接口


        
        $result = $pay->execute($request);
        if($pay->checkResult())
        {
            $clientRequest = new \Yurun\PaySDK\Weixin\APP\Params\Client\Request;
            $clientRequest->prepayid = $result['prepay_id'];
            $pay->prepareExecute($clientRequest, $url, $res);
            // var_dump($data); // 需要将这个数据返回给app端
            $result = $res;
        }
        else
        {
            $this->error($pay->getErrorCode() . ':' . $pay->getError());
            // var_dump($pay->getErrorCode() . ':' . $pay->getError());
        }

        // $result['mch_id'] = $result['partnerid'];
        // $result['prepay_id'] = $result['prepayid'];
        // $config['nonceStr'] = $result['noncestr'];
        // $config['package'] = $result['package'];
        // $config['timestamp'] = $result['timestamp'];
        // $config['nonceStr'] = $result['noncestr'];

        // $result['config'] = $config;
        $result['order'] = $data['order'];

        // $this->success('ok',$result);

        return $result;
    }




    /**
     * 查询微信订单(调试)
     * @ApiWeigh (998)
     * @param string $order 订单号
     * @return void
     */
    public function wechat_query_order_bug($order='SCOrder2021032399979710')
    {   
        $app = $this->get_pay_app();
        $data = $app->order->queryByOutTradeNumber($order);
        // halt($data);
        //查询是否支付成功
        if($data['result_code'] == 'FAIL'){//此订单没有支付过 ！微信未记录
            $this->error($data['err_code_des'],$data);
        }
        //trade_state自动成功就说明支付成功了！
        if ($data['return_code'] == 'SUCCESS' && $data['trade_state'] == 'SUCCESS') {
            //查询如果还没修改订状态就修改状态 ，

            // 统一写成返回支付等信息等必要字段；
            return json($data);

            



        }else{
            return json($data);
        }
    
        $orderdata = $this->get_order_data($order);
        return json($orderdata);

    }



    /**
     * 🔐微信支付钱包
     * @ApiWeigh (999)
     * @param array $data 订单信息
     * @return void
     */
    public function wx_pay_money_order($data)
    {

        //微信
        $this->_params = $this->get_wxpay_params($this->pay_role);
 
        // halt($this->_params);
        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\Weixin\SDK($this->_params);
        // 支付接口
        $request = new \Yurun\PaySDK\Weixin\APP\Params\Pay\Request;
        $request->body = '捷拉拉-充值'; // 商品描述
        $request->out_trade_no = $data['order']; // 订单号
        $request->total_fee = intval($data['money']*100); // 订单总金额，单位为：分
        // $request->spbill_create_ip = '127.0.0.1'; // 客户端ip，必须传正确的用户ip，否则会报错
        $request->notify_url = $this->domain.'api/query_pay/wechat_query_pay_money_order?order='.$data['order'];//$GLOBALS['PAY_CONFIG']['pay_notify_url']; // 异步通知地址
        // $request->scene_info->store_id = '门店唯一标识，选填';
        // $request->scene_info->store_name = '门店名称，选填';
        // 调用接口
        // halt($request);
        $result = $pay->execute($request);
        // halt($result);
        if($pay->checkResult())
        {
            $clientRequest = new \Yurun\PaySDK\Weixin\APP\Params\Client\Request;
            $clientRequest->prepayid = $result['prepay_id'];
            $pay->prepareExecute($clientRequest, $url, $res);
            // var_dump($data); // 需要将这个数据返回给app端
            $result = $res;
        }else{
            file_put_contents('pay.txt',$pay->getErrorCode() . ':' . $pay->getError());
            $this->error($pay->getErrorCode() . ':' . $pay->getError());
            // var_dump($pay->getErrorCode() . ':' . $pay->getError());
        }
        // $result['config'] = $config;
        $result['order'] = $data['order'];
        // $this->success('ok',$result);
        return $result;
    }




    
  



    /**
     * 🔐钱包支付订单
     * @ApiWeigh (999)
     * @param array $data 订单信息
     * @return void
     */
    public function money_pay_order($order_data,$ps=null)
    {
        // halt($data);
        //查询这个用户的余额是否等于大于
            //减去余额 修改状态
                    //写入钱包日志

        // $data['money']

    
        $this->MoneyPay($order_data['uid'],$order_data['money']);




       

        $data['pay_status'] = '2';//支付状态:1=待支付,2=已支付,3=已退款,4=已超时
        $data['pay_time'] = time();//支付时间
        $data['pay_type'] = '3';    //支付类型:1=微信,2=支付宝,3=钱包，9=其他
        $data['pay_money'] = $order_data['money']*100;//实际支付的金额 分


        $res_up = Db::name('pay_order')
                ->where('order',$order_data['order'])
                ->update($data);
        
        //修改主订单  订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=专线
        $db = $this->GetTableByOrderStatus($order_data['order_status']);
     
        //角色:1=货主,2=司机
        switch ($order_data['role_status']) {
            case '1':
                $pay_status['spay_status'] = '1';
                $pay_status['pay_time'] = $data['pay_time'];
                break;
            case '2':
                $pay_status['jpay_status'] = '1';
                break;
            default:
                # code...
                break;
        }
        Db::name($db)->where('id',$order_data['order_id'])->update($pay_status);

        


        $result['order'] = $data['order'];

        return $result;
    }






     /**
     * 🔐微信支付司机Vip订单
     * @ApiWeigh (999)
     * @ApiInternal
     * @param array $data 订单信息
     * @return void
     */
    public function wx_pay_jvip_order($data)
    {
        //微信
        $params = $this->get_wxpay_params($this->pay_role);
        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\Weixin\SDK($params);
        // 支付接口
        $request = new \Yurun\PaySDK\Weixin\APP\Params\Pay\Request;
        $request->body = '捷拉拉-VIP支付'; // 商品描述
        $request->out_trade_no = $data['order']; // 订单号
        $request->total_fee = $data['money']*100; // 订单总金额，单位为：分
        // $request->spbill_create_ip = '127.0.0.1'; // 客户端ip，必须传正确的用户ip，否则会报错
        $request->notify_url = $this->domain.'/api/query_pay/wechat_query_pay_jvip_order?order='.$data['order'];//$GLOBALS['PAY_CONFIG']['pay_notify_url']; // 异步通知地址
        // $request->scene_info->store_id = '门店唯一标识，选填';
        // $request->scene_info->store_name = '门店名称，选填';
        // 调用接口
        $result = $pay->execute($request);
        if($pay->checkResult())
        {
            $clientRequest = new \Yurun\PaySDK\Weixin\APP\Params\Client\Request;
            $clientRequest->prepayid = $result['prepay_id'];
            $pay->prepareExecute($clientRequest, $url, $res);
            // var_dump($data); // 需要将这个数据返回给app端
            $result = $res;
        }else{
            $this->error($pay->getErrorCode() . ':' . $pay->getError());
            // var_dump($pay->getErrorCode() . ':' . $pay->getError());
        }
        $result['order'] = $data['order'];
        // $this->success('ok',$result);
        return $result;
    }













    /**
     * 🔐微信支付发货人Vip订单
     * @ApiWeigh (999)
     * @ApiInternal
     * @param array $data 订单信息
     * @return void
     */
    public function wx_pay_svip_order($data)
    {
        //微信
        $params = $this->get_wxpay_params($this->pay_role);
        // SDK实例化，传入公共配置
        $pay = new \Yurun\PaySDK\Weixin\SDK($params);
        // 支付接口
        $request = new \Yurun\PaySDK\Weixin\APP\Params\Pay\Request;
        $request->body = '捷拉拉-VIP支付'; // 商品描述
        $request->out_trade_no = $data['order']; // 订单号
        $request->total_fee = $data['money']*100; // 订单总金额，单位为：分
        // $request->spbill_create_ip = '127.0.0.1'; // 客户端ip，必须传正确的用户ip，否则会报错
        $request->notify_url = $this->domain.'/api/query_pay/wechat_query_pay_svip_order?order='.$data['order'];//$GLOBALS['PAY_CONFIG']['pay_notify_url']; // 异步通知地址
        // $request->scene_info->store_id = '门店唯一标识，选填';
        // $request->scene_info->store_name = '门店名称，选填';
        // 调用接口
        $result = $pay->execute($request);
        if($pay->checkResult())
        {
            $clientRequest = new \Yurun\PaySDK\Weixin\APP\Params\Client\Request;
            $clientRequest->prepayid = $result['prepay_id'];
            $pay->prepareExecute($clientRequest, $url, $res);
            // var_dump($data); // 需要将这个数据返回给app端
            $result = $res;
        }else{
            $this->error($pay->getErrorCode() . ':' . $pay->getError());
            // var_dump($pay->getErrorCode() . ':' . $pay->getError());
        }
        $result['order'] = $data['order'];
        // $this->success('ok',$result);
        return $result;
    }









    /**
     * 支付宝回调
     * @ApiInternal
     * @return void
     */
    public function ali_pay_money_order_query($order=null)
    {
        if(!$order){
            $order = date('Y_m_d_H_i_s.ali');
        }
        $params = $this->request->param();
        if($params){
            file_put_contents('./alipaylog/'.$order,json_encode($params));

            if($params['trade_status']=='TRADE_SUCCESS'){
                $order_data = Db::name('money_order')->where('order',$params['out_trade_no'])->find();
                if($order_data){
                    $ok = false;
                    switch($order_data['pay_status']) {//支付状态:1=待支付,2=已支付,3=已退款,4=已超时
                        case '1':
                            //给用户加钱包日志
                            $UserMoney = $this->IncUserMoney($order_data['uid'],$params['total_amount'],'支付宝支付');
                            $ok = true;
                            break;
                        case '2':
                            //不做任何处理
                            break;
                        case '3':
                            //不做任何处理
                            break;
                        case '4':
                            //给用户加钱包日志
                            $UserMoney = $this->IncUserMoney($order_data['uid'],$params['total_amount'],'支付宝支付');
                            $ok = true;
                            break;
                        default:
                            # 不做任何处理
                            break;
                    }

                    if($ok){
                        $up_data['pay_status'] = 2;//支付状态:1=待支付,2=已支付,3=已退款,4=已超时
                        $up_data['pay_money'] = $params['total_amount']*100;//实际支付（分）
                        $up_data['pay_time'] = strtotime($params['gmt_payment']);
                        $up_data['before'] = $UserMoney['before'];
                        $up_data['after'] = $UserMoney['after'];
                        Db::name('money_order')->where('order',$params['out_trade_no'])->update($up_data);
                    }
                }
            }


            $this->success();
        }
        // "order": "Money2021100915141514",
        // "gmt_create": "2021-10-09 15:59:24",
        // "charset": "utf-8",
        // "seller_email": "yunhegang12@163.com",
        // "subject": "捷拉拉充值",
        // "sign": "Ei6ZN/lrHWKG/zyjvB4DQNeKN4XXgUYyY/fxbUpM+Ed8yU13sTekOYgSoL2JHlVaHTXi26tcsx5ao5B1LTUpRRQnZpM4RrU1DPwVKAbpQeu7LQ7ibKJsUy6ePaCCMhuHAivyvfBHEWvCF6mEH1HSr8TZ5H7HkxorPgKIlMclwFGtu5wOl1c5FzBb3RUQ3lrPpVLsPWCmGRypwp3KCHVeeNLnN86oDh9V+CYBJiIyPhmTNRYeFz5aTa+rxP0d9BdcnEXboL4XdyxqWxJZfOZzveMBCchpyBmicHAgQ2m5s4S3kHIE4Veub6JH7u5JmO0yku+aI1tcTk19nsgvTAMGxw==",
        // "body": "捷拉拉",
        // "buyer_id": "2088502079674473",
        // "invoice_amount": "0.01",
        // "notify_id": "2021100900222155925074471403301699",
        // "fund_bill_list": "[{&quot;amount&quot;:&quot;0.01&quot;,&quot;fundChannel&quot;:&quot;ALIPAYACCOUNT&quot;}]",
        // "notify_type": "trade_status_sync",
        // "trade_status": "TRADE_SUCCESS",
        // "receipt_amount": "0.01",
        // "app_id": "2021002181608598",
        // "buyer_pay_amount": "0.01",
        // "sign_type": "RSA2",
        // "seller_id": "2088041347755974",
        // "gmt_payment": "2021-10-09 15:59:25",
        // "notify_time": "2021-10-09 15:59:25",
        // "version": "1.0",
        // "out_trade_no": "Money2021100915141514",
        // "total_amount": "0.01",
        // "trade_no": "2021100922001474471457323783",
        // "auth_app_id": "2021002181608598",
        // "buyer_logon_id": "496***@qq.com",
        // "point_amount": "0.00"
        
       
    }


 



    
  

    



}